#!/bin/sh
echo "----------Start--------------"
Name="mybeego"
chmod +x "$Name"

# 精确匹配进程名
count=$(pgrep -x "$Name" | wc -l)

if [ "$count" -eq 0 ]; then
    echo "$Name is starting!!!"
    nohup ./"$Name" >> "$Name.log" 2>&1 &
    sleep 1  # 等待进程启动

    # 更可靠的PID获取方式
    if ID=$(pgrep -x "$Name"); then
        echo "$Name started! pid= $ID"
    else
        echo "Failed to start $Name!"
        exit 1
    fi
else
    ID=$(pgrep -x "$Name")
    echo "$Name already running! pid= $ID"
fi

echo "-----end-----"